package com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ruoyi.pingan.annotation.CommonLog;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.entity.FywCategoryTemplate;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.entity.FywCategoryTemplateDto;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.param.FywCategoryTemplateAddParam;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.param.FywCategoryTemplateEditParam;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.param.FywCategoryTemplateIdParam;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.param.FywCategoryTemplatePageParam;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.service.FywCategoryTemplateService;
import com.ruoyi.pingan.fymodule.thirdpa.util.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 分账品类模板表控制器
 *
 * @author zjf
 * @date  2025/07/29 15:14
 */
@Tag(name = "分账品类模板表控制器")
@RestController
@Validated
public class FywCategoryTemplateController {

    @Resource
    private FywCategoryTemplateService fywCategoryTemplateService;



    /**
     * 获取分账品类模板表分页
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "获取分账品类模板表分页")
    @SaCheckPermission("/biz/categorytemplate/page")
    @GetMapping("/biz/categorytemplate/page")
    public CommonResult<Page<FywCategoryTemplateDto>> page(FywCategoryTemplatePageParam fywCategoryTemplatePageParam) {
        return CommonResult.data(fywCategoryTemplateService.page(fywCategoryTemplatePageParam));
    }

    /**
     * 新增按钮返回商品大类
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "新增按钮返回商品大类")
    @CommonLog("新增按钮返回商品大类")
    @SaCheckPermission("/biz/categorytemplate/new")
    @PostMapping("/biz/categorytemplate/new")
    public CommonResult<FywCategoryTemplateDto> newCategory(@RequestBody @Valid FywCategoryTemplateAddParam fywCategoryTemplateAddParam) {
        return CommonResult.data(fywCategoryTemplateService.newCategory(fywCategoryTemplateAddParam));
    }


    /**
     * 添加分账品类模板表
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "添加分账品类模板表")
    @CommonLog("添加分账品类模板表")
    @SaCheckPermission("/biz/categorytemplate/add")
    @PostMapping("/biz/categorytemplate/add")
    public CommonResult<String> add(@RequestBody @Valid FywCategoryTemplateAddParam fywCategoryTemplateAddParam) {
        fywCategoryTemplateService.add(fywCategoryTemplateAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑分账品类模板表
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "编辑分账品类模板表")
    @CommonLog("编辑分账品类模板表")
    @SaCheckPermission("/biz/categorytemplate/edit")
    @PostMapping("/biz/categorytemplate/edit")
    public CommonResult<String> edit(@RequestBody @Valid FywCategoryTemplateEditParam fywCategoryTemplateEditParam) {
        fywCategoryTemplateService.edit(fywCategoryTemplateEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除分账品类模板表
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "删除分账品类模板表")
    @CommonLog("删除分账品类模板表")
    @SaCheckPermission("/biz/categorytemplate/delete")
    @PostMapping("/biz/categorytemplate/delete")
    public CommonResult<String> delete(@RequestBody @Valid FywCategoryTemplateIdParam fywCategoryTemplateIdParamList) {
        fywCategoryTemplateService.delete(fywCategoryTemplateIdParamList);
        return CommonResult.ok();
    }

    /**
     * 是否默认设置唯一性
     *
     * @author zjf
     * @date  2025/07/31 15:14
     */
    @Operation(summary = "是否默认设置")
    @CommonLog("是否默认设置")
    @SaCheckPermission("/biz/categorytemplate/defaultset")
    @PostMapping("/biz/categorytemplate/defaultset")
    public CommonResult<String> defaultset(@RequestBody @Valid FywCategoryTemplateIdParam fywCategoryTemplateIdParamList) {
        fywCategoryTemplateService.defaultset(fywCategoryTemplateIdParamList);
        return CommonResult.ok();
    }



    /**
     * 获取分账品类模板表详情
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "获取分账品类模板表详情")
    @SaCheckPermission("/biz/categorytemplate/detail")
    @GetMapping("/biz/categorytemplate/detail")
    public CommonResult<FywCategoryTemplate> detail(@Valid FywCategoryTemplateIdParam fywCategoryTemplateIdParam) {
        return CommonResult.data(fywCategoryTemplateService.detail(fywCategoryTemplateIdParam));
    }

    /**
     * 下载分账品类模板表导入模板
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "下载分账品类模板表导入模板")
    @GetMapping(value = "/biz/categorytemplate/downloadImportTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void downloadImportTemplate(HttpServletResponse response) throws IOException {
        fywCategoryTemplateService.downloadImportTemplate(response);
    }

    /**
     * 导入分账品类模板表
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "导入分账品类模板表")
    @CommonLog("导入分账品类模板表")
    @SaCheckPermission("/biz/categorytemplate/importData")
    @PostMapping("/biz/categorytemplate/importData")
    public CommonResult<JSONObject> importData(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(fywCategoryTemplateService.importData(file));
    }

    /**
     * 导出分账品类模板表
     *
     * @author zjf
     * @date  2025/07/29 15:14
     */
    @Operation(summary = "导出分账品类模板表")
    @SaCheckPermission("/biz/categorytemplate/exportData")
    @PostMapping(value = "/biz/categorytemplate/exportData", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportData(@RequestBody List<FywCategoryTemplateIdParam> fywCategoryTemplateIdParamList, HttpServletResponse response) throws IOException {
        fywCategoryTemplateService.exportData(fywCategoryTemplateIdParamList, response);
    }
}
